#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
    
};
struct  TreeNode* BuyNode(int n)
{
    struct  TreeNode* root = (struct  TreeNode*)malloc(sizeof(struct  TreeNode));
    if (root == NULL)
    {
        perror("malloc fail");
    }
    root->val = n;
    root->left = NULL;
    root->right = NULL;
    return root;
}

struct  TreeNode* CreateTree()
{
    struct TreeNode* node1 = BuyNode(5);
    struct TreeNode* node2 = BuyNode(4);
    struct TreeNode* node3 = BuyNode(8);
    struct TreeNode* node4 = BuyNode(11);
    struct TreeNode* node5 = BuyNode(13);
    struct TreeNode* node6 = BuyNode(4);
    struct TreeNode* node7 = BuyNode(7);
    struct TreeNode* node8 = BuyNode(2);
    struct TreeNode* node9 = BuyNode(1);
    node1->left = node2;
    node1->right = node3;
    node2->left = node4;
    node4->left = node7;
    node4->right = node8;
    node3->left = node5;
    node3->right = node6;
    node6->right = node9;
    return node1;
}
bool hasPathSum(struct TreeNode* root, int targetSum) {
    if (root == NULL)
        return 0;
    if (targetSum <= root->val)
        targetSum -= root->val;
    if (targetSum == 0)
        return true;
    return hasPathSum(root->left, targetSum) || hasPathSum(root->right, targetSum);
}
int main()
{
    struct  TreeNode* root = CreateTree();
    hasPathSum(root, 22);
    return 0;
}